package api

import (
	"getaway/basic/config"
	__ "getaway/basic/proto/orderproto"
	"getaway/handler/request"
	"getaway/handler/response"
	"github.com/gin-gonic/gin"
)

// AddFence
// @Summary      添加围栏
// @Description  添加围栏
// @Tags         围栏模块
// @Accept       json
// @Produce      json
// @Param        fence   body    request.AddFenceReq    true  "围栏参数"
// @Success      200  {object}  response.Response
// @Failure      400  {object}  response.Response
// @Failure      500  {object}  response.Response
// @Router       /vehicle/addFence [post]
// @Security TokenAuth
func AddFence(c *gin.Context) {
	var req request.AddFenceReq
	if err := c.ShouldBind(&req); err != nil {
		response.ParameterError(c, "参数错误", err.Error())
		return
	}
	fence, err := config.OrderClient.CreateFence(c, &__.CreateFenceReq{
		CityId:      req.CityId,
		Name:        req.Name,
		Type:        req.Type,
		Latitude:    float32(req.Latitude),
		Longitude:   float32(req.Longitude),
		Coordinates: req.Coordinates,
		Description: req.Description,
		Status:      req.Status,
	})
	if err != nil {
		response.SrvError(c, "添加围栏失败", err.Error())
		return
	}
	response.Success(c, "添加围栏成功", fence)
}

// DeletedFence
// @Summary      删除围栏
// @Description  删除围栏
// @Tags         围栏模块
// @Accept       json
// @Produce      json
// @Param        fence   body    request.DeleteFenceReq    true  "围栏参数"
// @Success      200  {object}  response.Response
// @Failure      400  {object}  response.Response
// @Failure      500  {object}  response.Response
// @Router       /vehicle/deletedFence [post]
// @Security TokenAuth
func DeletedFence(c *gin.Context) {
	var req request.DeleteFenceReq
	if err := c.ShouldBind(&req); err != nil {
		response.ParameterError(c, "参数错误", err.Error())
		return
	}
	fence, err := config.OrderClient.DeletedFence(c, &__.DeletedFenceReq{
		Id: req.Id,
	})
	if err != nil {
		response.SrvError(c, "删除围栏失败", err.Error())
		return
	}
	response.Success(c, "删除围栏成功", fence)
}

// GetFence
// @Summary      删除围栏
// @Description  删除围栏
// @Tags         围栏模块
// @Accept       json
// @Produce      json
// @Param        vehicle   query   request.ListFenceResp    true  "围栏参数"
// @Success      200  {object}  response.Response
// @Failure      400  {object}  response.Response
// @Failure      500  {object}  response.Response
// @Router       /vehicle/getFence [get]
func GetFence(c *gin.Context) {
	var req request.ListFenceResp
	if err := c.ShouldBind(&req); err != nil {
		response.ParameterError(c, "参数错误", err.Error())
		return
	}
	fence, err := config.OrderClient.ListFence(c, &__.ListFenceReq{})
	if err != nil {
		response.SrvError(c, "展示围栏失败", err.Error())
		return
	}
	response.Success(c, "展示围栏成功", fence)
}

// DeletedFence
// @Summary      修改围栏
// @Description  修改围栏
// @Tags         围栏模块
// @Accept       json
// @Produce      json
// @Param        fence   body    request.UpdateFenceReq    true  "围栏参数"
// @Success      200  {object}  response.Response
// @Failure      400  {object}  response.Response
// @Failure      500  {object}  response.Response
// @Router       /vehicle/updateFence [post]
// @Security TokenAuth
func UpdateFence(c *gin.Context) {
	var req request.UpdateFenceReq
	if err := c.ShouldBind(&req); err != nil {
		response.ParameterError(c, "参数错误", err.Error())
		return
	}
	fence, err := config.OrderClient.UpdateFence(c, &__.UpdateFenceReq{
		Id:     req.Id,
		Status: req.Status,
	})
	if err != nil {
		response.SrvError(c, "修改围栏失败", err.Error())
		return
	}
	response.Success(c, "修改围栏成功", fence)
}
